package com.clstu.tankgame3;

import java.awt.*;
import java.util.Vector;

public class EnemyTank extends Tank implements Runnable{

    public EnemyTank(int x, int y) {
        super(x, y);
        this.setSpeed(1);
    }

    private void sleepPlus(){
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while (isLive()){//让敌人的坦克随机的动起来
            switch (super.getDirect()){
                case 0:
                    for (int i = 0; i < 30; i++) {
                        moveUP();
                        //sleepPlus();
                    }
                    break;
                case 1:
                    for (int i = 0; i <30; i++) {
                        moveLeft();
                        //sleepPlus();
                    }
                    break;
                case 2:
                    for (int i = 0; i <30; i++) {
                        moveDown();
                        //sleepPlus();
                    }
                    break;
                case 3:
                    for (int i = 0; i <30; i++) {
                        moveRight();
                      // sleepPlus();
                    }
                    break;
                default:
                    break;
            }
            sleepPlus();
            setDirect((int)(Math.random()*4));//改变方向
            //如果发射的子弹已经消亡，就重新发射一颗子弹
            if(getShots().size()<=5){//修改为敌方最多同时发射5颗子弹
                Shot shot=shot(Color.yellow);
                new Thread(shot).start();
                getShots().add(shot);
            }
        }
    }
}
